package thread;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

public class Myservice {
	private ReentrantLock lock = new ReentrantLock();
	private Condition condition = lock.newCondition();
	private boolean hasValue = false;

	public void set() {
		try {
			lock.lock();
			while (hasValue == true) {
				condition.await();
			}
			System.out.println("print @ ");
			hasValue = true;
			condition.signal();
		} catch (InterruptedException e) {
			lock.lock();
		}finally{
			lock.unlock();
		}
	}
	
	public void get(){
		try{
			lock.lock();
			while(hasValue==false){
				condition.await();
			}
			System.out.println("print * ");
			hasValue=false;
			condition.signal();
		}catch (InterruptedException e) {
			e.printStackTrace();
		}finally{
			lock.unlock();
		}
	}
	
	
}
